Skip to content

bootstrap: Detect musl hosts #144092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gelbpunkt
Copy link
Contributor

Currently, all non-Android Linux hosts are assumed to be using glibc. This obviously isn't very portable and will currently result in downloading a stage0 toolchain for glibc even on musl hosts.

There are multiple ways to detect musl somewhat reliably, but the easiest option is to check for the python target, which is exposed in sys.implementation._multiarch and has values like "x86_64-linux-gnu" or "powerpc64le-linux-musl".

@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

r? @albertlarsan68

rustbot has assigned @albertlarsan68.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jul 17, 2025
@Gelbpunkt
Copy link
Contributor Author

The alternative I would suggest is to check ldd --version for the string musl, but that would require a larger, more intrusive change, since it outputs to stderr, while the current command execution code only accounts for stdout. I think the python target is sufficient.

@Kobzol
Copy link
Member

Kobzol commented Jul 18, 2025

Is there a way to get this information in Python with public (i.e. not _) API?

@Gelbpunkt
Copy link
Contributor Author

Gelbpunkt commented Jul 18, 2025

Is there a way to get this information in Python with public (i.e. not _) API?

sysconfig.get_config_var("MULTIARCH") would also work, although from what I read in some cpython issues, SOABI is probably the preferred config var to check.

@Kobzol
Copy link
Member

Kobzol commented Jul 18, 2025

Ok. This looks simple enough. If it causes any trouble, we can later wrap it in a try/except block. There are some CPU architectures for which we have a GNU build, but don't have a MUSL build though:

~$ rustup target list -q | grep -e "-linux-gnu$"
aarch64-unknown-linux-gnu
i586-unknown-linux-gnu
i686-unknown-linux-gnu
loongarch64-unknown-linux-gnu
powerpc-unknown-linux-gnu
powerpc64-unknown-linux-gnu
powerpc64le-unknown-linux-gnu
riscv64gc-unknown-linux-gnu
s390x-unknown-linux-gnu
sparc64-unknown-linux-gnu
x86_64-unknown-linux-gnu
~$ rustup target list -q | grep -e "-linux-musl$"
aarch64-unknown-linux-musl
i586-unknown-linux-musl
i686-unknown-linux-musl
loongarch64-unknown-linux-musl
powerpc64le-unknown-linux-musl
riscv64gc-unknown-linux-musl
x86_64-unknown-linux-musl

Not sure if anyone runs bootstrap on s390x/sparc/powerpc/powerpc64...

If I understand it correctly, if -gnu stage0 is downloaded on a MUSL system, it's useless, because your system doesn't have glibc at all? In that case the missing architectures wouldn't be an issue, as bootstrap wouldn't work on them before anyway.

r? @Kobzol

@rustbot rustbot assigned Kobzol and unassigned albertlarsan68 Jul 18, 2025
@Gelbpunkt
Copy link
Contributor Author

Not sure if anyone runs bootstrap on s390x/sparc/powerpc/powerpc64...

I'm running it on powerpc64(le) at the moment x)

If I understand it correctly, if -gnu stage0 is downloaded on a MUSL system, it's useless, because your system doesn't have glibc at all?

Correct, the stage0 is completely useless and cannot be executed.

I would be very surprised to see someone with a Python build for musl bootstrapping rustc with glibc as their system libc.

@Kobzol
Copy link
Member

Kobzol commented Jul 18, 2025

I'm running it on powerpc64(le) at the moment x)

Well the le variant has a musl build :)

Ok, I agree that the described situation should be quite rare. Let's try.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 18, 2025

📌 Commit 2e99b18 has been approved by Kobzol

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 18, 2025
@Gelbpunkt
Copy link
Contributor Author

Should I really not change it to use sysconfig.get_config_var("SOABI")? I'm fine either way, just want to make sure you're okay with this as is

@Gelbpunkt
Copy link
Contributor Author

Well the le variant has a musl build :)

And here's the output on powerpc64-unknown-linux-musl host with this PR:

RuntimeError: src/stage0 doesn't contain a checksum for dist/2025-06-24/rust-std-beta-powerpc64-unknown-linux-musl.tar.xz. Pre-built artifacts might not be available for this target at this time, see https://doc.rust-lang.org/nightly/rustc/platform-support.html for more information.

@Kobzol
Copy link
Member

Kobzol commented Jul 18, 2025

Should I really not change it to use sysconfig.get_config_var("SOABI")? I'm fine either way, just want to make sure you're okay with this as is

Oh, I misunderstood your earlier comment, I somehow thought that "SOABI" refers to the way the arch is checked in the current version of this PR. In that case yes, please switch to the approach using public API.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 18, 2025
Currently, all non-Android Linux hosts are assumed to be using glibc.
This obviously isn't very portable and will currently result in
downloading a stage0 toolchain for glibc even on musl hosts.

There are multiple ways to detect musl somewhat reliably, but the
easiest option is to check for the python SOABI config variable, which
has values like "cpython-313-x86_64-linux-gnu" or
"cpython-313-powerpc64-linux-musl".

Signed-off-by: Jens Reidel <[email protected]>
@Gelbpunkt
Copy link
Contributor Author

Changed it to use SOABI :)

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 18, 2025
@Kobzol
Copy link
Member

Kobzol commented Jul 18, 2025

Thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 18, 2025

📌 Commit 9e4f777 has been approved by Kobzol

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants